var selectedRow = '';
var isInit = true;

$(function () {
    window.actionEvents = {
        'click .isvInfoView': function(e, value, row, index) {
            //编辑操作
            selectedRow = row;
            console.log(row);
            openCommonIsvPage(row.isvPid, 'checkBizDocApp');
        },
    };
    initTextSearch("#isvName",
        basePath + 'checkApp/checkDocApp/getIsvData?t='+new Date().getTime()+'&isvName=',
        ['isvPid', 'isvName'],
        {'isvPid':'服务商PID', 'isvName':'服务商名称'},
        'isvPid',
        'isvName',
        true,
        selectIsvValue,
        noSelectIsvValue,
        false
    );

    laydate.render({
        elem: '#timeInterval'
        ,type: 'datetime'
        ,range: true //或 range: '~' 来自定义分割字符
        // ,value: dateFtt("yyyy-MM-dd hh:mm:ss", preDate) + ' - ' + dateFtt("yyyy-MM-dd hh:mm:ss", curDate)
        //js赋值重置失效，改为就是怕、页面赋值
        ,isInitValue: true //是否允许填充初始值，默认为 true
    });

    laydate.render({
        elem: '#timeInterval1'
        ,type: 'datetime'
        ,range: true //或 range: '~' 来自定义分割字符
        // ,value: dateFtt("yyyy-MM-dd hh:mm:ss", preDate) + ' - ' + dateFtt("yyyy-MM-dd hh:mm:ss", curDate)
        //js赋值重置失效，改为就是怕、页面赋值
        ,isInitValue: true //是否允许填充初始值，默认为 true
    });

    //初始化操作
    if($("#status").val() == 'wait'){
        $("#unCheckDiv").show();
        $("#checkDiv").hide();
        $("#checkTypeDiv").hide();

        $("#detailBtn").hide();
        $("#checkBtn").show();

        $("#unCheckTable").show();
        $("#checkTable").hide();
    }else{
        $("#unCheckDiv").hide();
        $("#checkDiv").show();
        $("#checkTypeDiv").show();

        $("#detailBtn").show();
        $("#checkBtn").hide();

        $("#unCheckTable").hide();
        $("#checkTable").show();
    }
});

function selectIsvValue(data) {
    if (!data || !data.isvPid) {
        return;
    }
    $('#isvPid').val(data.isvPid);
}

function noSelectIsvValue() {
    $('#isvPid').val('');
}

function selectOrgValue(data) {
    if (!data || !data.orgCode) {
        return;
    }
    $('#orgCode').val(data.orgCode);
}

function noSelectOrgValue() {
    $('#orgCode').val('');
}

function changeStatus(value){
    if(value == 'wait'){
        $("#unCheckDiv").show();
        $("#checkDiv").hide();
        $("#checkTypeDiv").hide();
        $("#detailBtn").hide();
        $("#checkBtn").show();

        $("#unCheckTable").show();
        $("#checkTable").hide();
    }else{
        $("#unCheckDiv").hide();
        $("#checkDiv").show();
        $("#checkTypeDiv").show();
        $("#detailBtn").show();
        $("#checkBtn").hide();

        $("#unCheckTable").hide();
        $("#checkTable").show();
    }
    doRefresh();
}

function doRefresh() {
    selectedRow = '';
    if($("#status").val() == 'wait'){
        $('#dataTable').bootstrapTable('refresh', {
            url: basePath + 'checkApp/checkDocOrg/pageFindCheckedOrgAppData?t=' + new Date().getTime(),
        });
    }else{
        $('#dataTable1').bootstrapTable('refresh', {
            url: basePath + 'checkApp/checkDocOrg/pageFindCheckedOrgAppPublishData?t=' + new Date().getTime(),
        });
    }
}

function getParams(params) {
    var pageSize = params.pageSize;
    var pageNo = params.pageNumber;
    if (isInit) {
        isInit = false;
        pageSize = searchInfo.pageSize ? searchInfo.pageSize : params.pageSize;
        pageNo = searchInfo.pageNo ? searchInfo.pageNo : params.pageNumber;
    }
    var postData ={
        pageSize : pageSize,
        pageNo : pageNo
    };
    var status = $.trim($("#status").val());
    postData.orgName = $.trim($("#orgName").val());
    postData.isvPid = $.trim($("#isvPid").val());
    postData.checkType = $.trim($("#checkType").val());
    var gmtStart = '';
    var gmtEnd = '';
    var timeInterval = '';
    if(status == 'wait'){
        postData.result = status;
        timeInterval = $("#timeInterval").val();
    }else{
        postData.result = $.trim($("#results").val());
        timeInterval = $("#timeInterval1").val();
    }
    if(timeInterval){
        var dates = timeInterval.split(' - ');
        if(dates && dates.length >1){
            gmtStart = dates[0];
            gmtEnd = dates[1];
        }
    }
    postData.beginTimeStr = gmtStart;
    postData.endTimeStr = gmtEnd;
    postData.bizCode = $.trim($("#bizCode").val());
    return postData;
}


function formatOperateType(value, row, index) {
    return convertMapCodeText(OperateType,value);
}
function formatcheckResultTypeMap(value, row, index) {
    return checkResultTypeMap[value];
}

$("#dataTable").on("click-row.bs.table",function(e,row,ele){
    $("#dataTable .success").removeClass("success");
    $(ele).addClass("success");
    selectedRow = row;
});

$("#dataTable1").on("click-row.bs.table",function(e,row,ele){
    $("#dataTable1 .success").removeClass("success");
    $(ele).addClass("success");
    selectedRow = row;
});

function doDetail() {
    if (!selectedRow.id || selectedRow.id == '') {
        toastr.error(common_no_choose_msg.format("操作"));
        return;
    }
    var tableOptions = $('#dataTable1').bootstrapTable('getOptions', null);
    window.location.href = basePath + 'checkApp/checkDocOrg/pendingCheckOrgPageWin?id=' + selectedRow.id
        +"&batchId="+selectedRow.batchId +"&orgCode="+selectedRow.orgCode +
         '&hasOrg='+ defLogInfo.hasOrg + '&hasTeam='+ defLogInfo.hasTeam + '&hasApp='+ defLogInfo.hasApp +
        '&type=check' + '&t=' + new Date().getTime() + '&' + $('#searchForm').serialize() + '&pageNo=' + tableOptions.pageNumber + '&pageSize=' + tableOptions.pageSize;
}

function openCheckDocPage() {
    if (!selectedRow.id || selectedRow.id == '') {
        toastr.error(common_no_choose_msg.format("操作"));
        return;
    }
    var tableOptions = $('#dataTable').bootstrapTable('getOptions', null);
    window.location.href = basePath + 'checkApp/checkDocOrg/pendingCheckOrgPageWin?id=' + selectedRow.id
        +'&bizCodeApp=' + selectedRow.bizCodeApp+ '&appid=' + selectedRow.appidStr +"&batchId="+selectedRow.batchId +
        '&hasOrg='+ defLogInfo.hasOrg + '&hasTeam='+ defLogInfo.hasTeam + '&hasApp='+ defLogInfo.hasApp +
        '&type=wait' + "&orgCode="+selectedRow.orgCode+ '&t=' + new Date().getTime() + '&' + $('#searchForm').serialize() + '&pageNo=' + tableOptions.pageNumber + '&pageSize=' + tableOptions.pageSize;
}

function doReset(formId){
    var status = $("#status").val();
    var formObj = $("#" + formId);
    if(formId && formObj){
        formObj.clearForm(true);
    }
    if(status != 'wait'){
        changeStatus('wait');
    }
}

